{% extends "person/base.html" %}
{% load nm %}
{% load js %}

{% block head_resources %}
  {{block.super}}
  {% jsinclude "nm" %}
  {% jsinclude "tables" %}
{% endblock %}

{% block head %}
{{block.super}}
<script type="text/javascript">
$(function() {
    $(".proctable").tablesorter({
        textExtraction: function(node) {
            val = node.getAttribute("val");
            if (val == null)
                val = node.textContent || node.innerText;
            return val;
        },
    });
});
</script>
{% endblock %}

{% block content %}

<h1>{{person.fullname}}</h1>

<table class="personinfo">
    <tr><th>Account name</th><td>{{person.uid|default:"None chosen yet"}}</td></tr>
    <tr><th>OpenPGP fingerprint</th><td>{{person.fpr|fingerprint}}{% if "edit_ldap" in visit_perms %} (<a href="{% url 'fprs_person_list' key=person.lookup_key %}">manage</a>){% endif %}</td></tr>
    {% if "edit_email" in visit_perms %}
    <tr><th>Contact email</th><td>{{person.email}} <a href="{% url 'person_edit_email' key=person.lookup_key %}">[edit]</a></td></tr>
    {% endif %}
    <tr><th>Status</th><td>{{person.status|desc_status}} {% if person.status == STATUS_DC %}on nm.debian.org since{% else %}since{% endif %} {{person.status_changed|date:"Y-m-d"}}
    {% if person.changed_before_data_import %}
    (changed before data import)
    {% endif %}
    {% if "request_new_status" in visit_perms and person.possible_new_statuses %}(<a href="{% url 'process_create' key=person.lookup_key %}">request new status</a>){% endif %}
    </td></tr>
    {% if person.pending %}
    <tr><th>Pending</th><td>This is a new entry that requires confirmation before {{person.expires}}. Click <a href="{% url 'public_newnm_resend_challenge' key=person.lookup_key %}">here</a> to send the email challenge again.</td></tr>
    {% endif %}
    {% with am=person.am %}
      {% if am %}
      <tr>
          <th>Application manager</th>
          <td>
              {% if am.is_am %}active,{% endif %}
              {% if am.is_fd %}fd,{% endif %}
              {% if am.is_dam %}dam,{% endif %}
              {% if am.is_am_ctte %}am ctte,{% endif %}
              {{person.am.processed.count}} applicants processed
              {% if visitor.am == am or visitor.is_admin %}
              <a href="{% url 'restricted_amprofile' key=am.person.lookup_key %}">[preferences]</a>
              {% endif %}
              {% if visitor.is_admin %}
              <a href="{% url 'admin:backend_am_change' am.id %}">[admin]</a>
              {% endif %}
          </td>
      </tr>
      {% endif %}
    {% endwith %}
</table>

{% if "edit_ldap" in visit_perms %}
<a href="{% url 'person_edit_ldap' key=person.lookup_key %}">edit LDAP information</a>
{% endif %}

{% if person.is_am %}
{% if visitor.is_am or visitor.is_admin %}
<a href="{% url 'restricted_amprofile' key=person.lookup_key %}">edit AM</a>
{% endif %}
{% endif %}

<h2>Short Biography</h2>

<div class="personbio">
{% if person.bio %}
  <div class="expanded">
    {{bio_html|safe}}
  </div>
  <div class="collapsed">
    {{person.bio|truncatechars:128}}{% if person.bio|length > 128 %} <span class="expander">(expand)</span>{% endif %}
  </div>
{% else %}
  (missing)
{% endif %}
</div>

{% if "edit_bio" in visit_perms %}
<a href="{% url 'person_edit_bio' key=person.lookup_key %}">[edit]</a>
{% endif %}

<h2>Personal history</h2>

{% include "process/process_list.html" with procs=processes2 proctable_archive=True %}

{% include "public/person_process_table.html" with p=p processes=processes only %}

{% if adv_processes %}

<h2>Advocate history</h2>

{% include "process/process_list.html" with procs=adv_processes2 proctable_archive=True %}

{% include "public/person_process_table.html" with p=p processes=adv_processes only %}

{% endif %}

{% if am %}

<h2>AM history</h2>

{% include "process/process_list.html" with procs=am_processes2 proctable_archive=True %}

{% include "public/person_process_table.html" with p=p processes=am_processes only %}

{% endif %}

{% if audit_log %}

<h2>Audit log</h2>

<table>
  <thead>
    <tr>
      <th>Date</th>
      <th>Author</th>
      <th>Notes</th>
      <th>Changes</th>
    </tr>
  </thead>
  <tbody>
    {% for e in audit_log %}
    <tr>
      <td>{{e.logdate|date:"Y-m-d H:i:s"}}</td>
      <td><a href="{{e.author.get_absolute_url}}">{{e.author}}</a></td>
      <td>{{e.notes}}</td>
      <td>
        <ul>
        {% for field, old, new in e.changes %}
        <li>{{field}}: {{old}} → {{new}}</li>
        {% endfor %}
        </ul>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>

{% endif %}

{% endblock %}
